package ProductAndConsumer;

public class Producer implements Runnable {
    private Num num;

    public Num getNum() {
        return num;
    }

    public void setNum(Num num) {
        this.num = num;
    }

    public Producer() {
    }

    public Producer(Num num) {
        this.num = num;
    }

    @Override


    public void run() {//输出奇数
        while (true) {
            synchronized (this.num) {
                if (this.num.getNum() % 2 == 0) {
                    try {
                        this.num.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                this.num.setNum(this.num.getNum() + 1);
                try {
                    Thread.sleep(1000 * 1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName() + "------>" + this.num.getNum());
                this.num.notifyAll();
            }
        }

    }

}
